package com.item.service.Impl;

import com.item.mapper.ArticleMapper;
import com.item.pojo.Article;
import com.item.pojo.Page;
import com.item.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public List<Article> selectAll() {
        return articleMapper.selectAll();
    }

    @Override
    public Article selectById(Integer id) {
        return articleMapper.selectById(id);
    }

    @Override
    public List<Article> selectByCollect() {
        return articleMapper.selectByCollect();
    }

    @Override
    public List<Article> selectByType(String type) {
        return articleMapper.selectByType(type);
    }

    @Override
    public Map<String, Object> pageList(Integer pageSize, Integer page,String title,String type) {

        Map<String, Object> map=new HashMap<>();
        Page<Article> articlePage = new Page<>();

        Integer start=(page-1)*pageSize;

        articlePage.setStart(start);
        articlePage.setPageSize(pageSize);

        Article article=new Article();
        article.setTitle(title);
        article.setType(type);

        articlePage.setData(article);

        // 查询当前页数据
        List<Article> articleList =  articleMapper.pageList(articlePage);

        // 查询总记录数
        Integer total =  articleMapper.pageCount(article);

        map.put("total",total);

        System.out.println();
        map.put("obj",articleList);

        return map;
    }

    @Override
    public int update(Article article) {
        return articleMapper.update(article);
    }

    @Override
    public int insert(Article article) {
        return articleMapper.insert(article);
    }

    @Override
    public int insertBatch(List<Article> articles) {
        return articleMapper.insertBatch(articles);
    }

    @Override
    public int delete(Integer id) {
        return articleMapper.delete(id);
    }

    @Override
    public int delBatch(List<Integer> id) {
        return articleMapper.delBatch(id);
    }
}
